package com.gxa.modules.pc.order.controller;

import com.gxa.common.utils.Result;
import com.gxa.common.utils.TPage;
import com.gxa.modules.pc.order.service.BookRegisterService;
import com.gxa.modules.model.entity.book.BookRegister;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 预约挂号表 前端控制器
 * </p>
 *
 * @author zhuiyi
 * @since 2022-11-12 09:47:44
 */
@Slf4j
@RestController
@Api(tags = "预约挂号")
public class BookRegisterController {


    @Autowired
    private BookRegisterService bookRegisterService;

    @ApiOperation("查询所有  预约挂号")
//    @RequiresPermissions("sys:user:list")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "pageNum",value = "当前在那一页",dataType = "String",defaultValue = "1"),
            @ApiImplicitParam(paramType = "query",name = "pageSize",value = "每页多少条记录",dataType = "String",defaultValue = "10"),
            @ApiImplicitParam(paramType = "query",name = "orderField",value = "根据什么字段排序",dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "order",value = "升序-asc 降序-desc （不是asc都是降序）",dataType = "String"),

            @ApiImplicitParam(paramType = "query",name = "name",value = "医生或病人的名称",dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "id",value = "用户id",dataType = "int"),
            @ApiImplicitParam(paramType = "query",name = "status",value = "就诊状态",dataType = "int"),
            @ApiImplicitParam(paramType = "query",name = "startTime",value = "时间范围-start（该参数用于查找在预约时间该时间范围内的）",dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "endTime",value = "时间范围-end（该参数用于查找在预约时间该时间范围内的）",dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "departmentId",value = "科室id",dataType = "String"),
    })
    @GetMapping("/list")
    public Result list(@RequestParam @ApiIgnore HashMap<String,Object> searchMap){
        log.info("---------------{}-------------",searchMap);
        TPage tPage = bookRegisterService.queryByPage(searchMap);
        return new Result().ok(tPage);
    }

    @ApiOperation("新增  预约挂号")
    @PostMapping("/book-register/add")
    public Result add(@RequestBody BookRegister bookRegister) {
        boolean save = bookRegisterService.save(bookRegister);
        if (save) {
            return new Result().ok();
        }
        return new Result().error();
    }
    @ApiOperation("删除  预约挂号")
    @PostMapping("/book-register/del")
    public Result add(@RequestBody List<Integer> ids) {
        if (bookRegisterService.removeByIds(ids)) {
            return new Result().ok();
        }
        return new Result().error();
    }
    @ApiOperation("保存备注  预约挂号")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "remark",value = "备注",dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "id",value = "预约单id",dataType = "int"),
    })
    @PostMapping("/book-register/save")
    public Result update(@RequestParam String remark,@RequestParam Integer id) {
        BookRegister byId = bookRegisterService.getById(id);
        if (byId ==null){
            return new Result().error();
        }
        byId.setRemark(remark);
        if (bookRegisterService.updateById(byId)) {
            return new Result().ok();
        }
        return new Result().error();
    }

    @ApiOperation("查看详情  预约挂号")
    @PostMapping("/book-register/{id}")
    public Result update(@ApiParam(value = "预约单id",required = true) @PathVariable("id") Integer id) {
        BookRegister byId = bookRegisterService.getById(id);
        if (byId ==null){
            return new Result().error();
        }
        return new Result().ok(byId);
    }


}
